package com.awspaas.user.apps.publicservice.bean;

import com.actionsoft.bpms.bo.engine.BO;
import com.alibaba.fastjson.JSON;

import java.io.Serializable;
import java.text.SimpleDateFormat;

/**
 * @Author Lizj
 * @Date 2021-6-17 16:32
 */
public class AwsLog implements Serializable {
    private AwsLog(){}
    public static final String SUCCESS = "1";
    public static final String ERROR = "0";
    public static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    private BO bo;// 定义返回数据

    //  定义接口开始执行时间
    private long callStartTime;//创建时间
    private String applicationName;// 系统标识
    private String CALL_METHOD;// 接口方法
    private String methodMSG;//调用名称
    private String callUID;// 调用账户（发送人账户）
    private String receiveUID;// 相关用户
    private String requestData;// 接口入参
    private String toDoSystemID;// 系统标识
    private String processInstId;// 流程实例ID
    private String toDoID;// 待办ID
    private String businessId;// 业务ID
    private String TrustContractID;// 信托合同ID
    private String clientID;// 委托人ID
    private String projectID;// 项目ID
    private String transactionOrderID;// 交易单ID
    private String investmentContractID;// 投资合同ID
    private String extInfo;// 扩展参数


    public static AwsLog awsLog(String applicationName, String CALL_METHOD, String methodMSG, String callUID,
                                String receiveUID, String requestData, String toDoSystemID,
                                String processInstId, String toDoID, String businessId, String TrustContractID,
                                String  clientID, String projectID, String transactionOrderID,
                                String investmentContractID, String extInfo) {
        AwsLog awsLog = new AwsLog();
        awsLog.callStartTime = System.currentTimeMillis();
        awsLog.applicationName = applicationName;
        awsLog.CALL_METHOD = CALL_METHOD;
        awsLog.methodMSG = methodMSG;
        awsLog.callUID = callUID;
        awsLog.receiveUID = receiveUID;
        awsLog.requestData = requestData;
        awsLog.toDoSystemID = toDoSystemID;
        awsLog.processInstId = processInstId;
        awsLog.toDoID = toDoID;
        awsLog.businessId = businessId;
        awsLog.TrustContractID = TrustContractID;
        awsLog.clientID = clientID;
        awsLog.projectID = projectID;
        awsLog.transactionOrderID = transactionOrderID;
        awsLog.investmentContractID = investmentContractID;
        awsLog.extInfo = extInfo;
        return awsLog;
    }

    public void end(String result, Response response){
        long callEndTime = System.currentTimeMillis();
        // 创建接口日志bo
        bo = new BO();
        // 调用方法
        bo.set("CALL_METHOD", CALL_METHOD);
        // 调用方法名称
        bo.set("METHOD_MSG", methodMSG);
        // 调用用户
        bo.set("CALL_UID", callUID);
        // 相关用户
        bo.set("RECEIVE_UID", receiveUID);
        // 调用时间
        bo.set("CALL_TIME", sdf.format(callStartTime));
        // 入参
        bo.set("INTERFACE_PARAMETER", requestData);
        // 结束时间
        bo.set("CALL_END_TIME", sdf.format(callEndTime));
        // 接口执行时间
        bo.set("AGING", callEndTime-callStartTime);
        // 是否成功
        bo.set("ISSUCCESS", result);
        // 出参
        bo.set("OUTPARAMETER", JSON.toJSONString(response.getData()));
        // 待办系统标识
        bo.set("TO_DO_SYSTEM_ID", toDoSystemID);
        //流程实例ID
        bo.set("TO_DO_PROCESSINSTID", response.getData().getProcess_InstID());
        // 待办ID
        bo.set("TO_DO_ID", toDoID);
        //业务ID
        bo.set("TO_DO_BUSINESSID", businessId);
        //信托合同ID
        bo.set("TRUSTCONTRACTID", TrustContractID);
        //委托人ID
        bo.set("CLIENTID", clientID);
        //项目ID
        bo.set("PROJECTID", projectID);
        //交易单ID
        bo.set("TRANSACTIONORDERID", transactionOrderID);
        //投资合同ID
        bo.set("INVESTMENTCONTRACTID", investmentContractID);
        //扩展参数
        bo.set("EXTINFO", extInfo);
    }

	public BO getBo(){
        return this.bo;
    }

    public long getCallStartTime() {
        return callStartTime;
    }

    public void setCallStartTime(long callStartTime) {
        this.callStartTime = callStartTime;
    }

    public String getCmd() {
        return CALL_METHOD;
    }

    public void setCmd(String cmd) {
        this.CALL_METHOD = cmd;
    }

    public String getMethodMSG() {
        return methodMSG;
    }

    public void setMethodMSG(String methodMSG) {
        this.methodMSG = methodMSG;
    }

    public String getCallUID() {
        return callUID;
    }

    public void setCallUID(String callUID) {
        this.callUID = callUID;
    }

    public String getReceiveUID() {
        return receiveUID;
    }

    public void setReceiveUID(String receiveUID) {
        this.receiveUID = receiveUID;
    }

    public String getRequestData() {
        return requestData;
    }

    public void setRequestData(String requestData) {
        this.requestData = requestData;
    }

    public String getToDoSystemID() {
        return toDoSystemID;
    }

    public void setToDoSystemID(String toDoSystemID) {
        this.toDoSystemID = toDoSystemID;
    }

    public String getToDoID() {
        return toDoID;
    }

    public void setToDoID(String toDoID) {
        this.toDoID = toDoID;
    }

    public String getProcessInstId() {
        return processInstId;
    }

    public void setProcessInstId(String processInstId) {
        this.processInstId = processInstId;
    }

    public String getBusinessId() {
        return businessId;
    }

    public void setBusinessId(String businessId) {
        this.businessId = businessId;
    }

    public static String getSUCCESS() {
        return SUCCESS;
    }

    public String getExtInfo() {
        return extInfo;
    }

    public void setExtInfo(String extInfo) {
        this.extInfo = extInfo;
    }
}
